<!--
 * @Description: 项目详情
 * @Author: lz
 * @Date: 2022-12-24 12:19:36
 * @LastEditTime: 2022-12-28 18:50:14
 * @LastEditors: lz
-->
<template>
  <div class="detail-wrap">
    <div class="detail-head">
      <div class="tag"></div>
      <div class="title">项目信息</div>
      <el-button type="primary" @click="add">认领项目</el-button>
    </div>
    <div class="detail-content">
      <PaTable v-if="detailId" :detailId="detailId"></PaTable>
    </div>
    <DialogWrap dialogTitle="时间节点设置" :dialogVisible.sync="dialogVisible">
      <template #content>
        <el-form :model="formDialog" label-width="220px">
          <el-form-item label="领取施工许可证时间节点：">
            <el-date-picker v-model="formDialog.licenceTime" type="date" placeholder="选择日期"></el-date-picker>
          </el-form-item>
          <el-form-item label="项目竣工验收时间节点：">
            <el-date-picker
              v-model="formDialog.completionAcceptanceTime"
              type="date"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
        </el-form>
      </template>
      <template #footer>
        <el-button type="primary" plain @click="onClose()">取 消</el-button>
        <el-button type="primary" @click="onDialogEdit()">确认并认领</el-button>
      </template>
    </DialogWrap>
  </div>
</template>

<script>
import { addAdoptProject } from "@/api/homeApi";
import PaTable from "@/components/PaTable";
import DialogWrap from "@/components/DialogWrap";
export default {
  components: {
    PaTable,
    DialogWrap
  },
  data () {
    return {
      detailId: null,
      dialogVisible: false,
      formDialog: {
        licenceTime: "",
        completionAcceptanceTime: ""
      }
    };
  },
  created () {
    this.detailId = this.$route.query.id;
  },
  methods: {
    onDialogEdit () {
      if (!this.formDialog.licenceTime) {
        return this.$message({
          message: '请选择领取施工许可证时间节点',
          type: "error"
        });
      }
      if (!this.formDialog.completionAcceptanceTime) {
        return this.$message({
          message: '请选择项目竣工验收时间节点',
          type: "error"
        });
      }
      addAdoptProject({
        id: this.detailId,
        agencyPeople: JSON.parse(localStorage.getItem("P-User-Info")).id,
        licenceTime: this.formDialog.licenceTime,
        completionAcceptanceTime: this.formDialog.completionAcceptanceTime,
      }).then(res => {
        this.formDialog = {
          licenceTime: "",
          completionAcceptanceTime: ""
        }
        this.$message({
          message: res.msg,
          type: "success"
        });
        this.$router.push("/home/center");
      });
    },
    add () {
      this.dialogVisible = true;
    },
    onClose () {
      this.dialogVisible = false;
      this.formDialog = {
        licenceTime: "",
        completionAcceptanceTime: ""
      }
    },
  }
};
</script>
<style lang="scss" scoped>
.detail-wrap {
  background: #ffffff;
  box-shadow: 0px 6px 58px 0px rgba(196, 203, 214, 0.1);
  border-radius: 24px;
  padding: 39px 53px;
  .detail-head {
    padding-left: 10px;
    display: flex;
    margin-bottom: 40px;
    .tag {
      width: 11px;
      height: 45px;
      background: #2f86fd;
      border-radius: 6px;
      margin-right: 26px;
    }
    .title {
      font-size: 36px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #0a1629;
      margin-right: 61px;
    }
  }
}
</style>
